import { request } from './request';
import axios, {post} from "axios";
import {Ref, ref} from "vue";

//导出login方法，供其它地方使用
export function test1(businessid) {
    let url = "/FoodController/listFoodByBusinessId/"
    return request({
        url: url.concat(businessid),
        method: 'get',
    })
}
export function test2(data) { //post接收的对象一定需要 命名为data，这样request.ts的transformRequest配置才可以识别
    let url = "/UserController/getUserByIdByPass"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function test3(data) { //如果后端是@RequestParam的话，直接改成post方法（前后端都是
    let url = "/CartController/removeCart"
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function listShops() {
    let url = "/shop/listShops"
    return request({
        url: url,
        method: 'get'
    })
}

export function businessRegister(data) {
    let url = "/business/register"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function customerRegister(data) {
    let url = "/customer/register"
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function businessLogin(data) {
    let url = "/business/login"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function customerLogin(data) {
    let url = "/customer/login"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function checkUser(username) {
    let url = "/user/check/"
    return request({
        url: url.concat(username),
        method: 'get'
    })
}

export function businessListShops(data) { //如果后端是@RequestParam的话，直接改成post方法（前后端都是
    let url = "/business/get"
    return request({
        url: url,
        method: 'post',
        data
    })
}
export function businessListShopItems(data) { //如果后端是@RequestParam的话，直接改成post方法（前后端都是
    let url = "/shop/get"
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function browseOrderLineItem(orderId) {
    let url = "/lineItem/browseLineItem/"+orderId
    return request({
        url: url,
        method: 'get',
    })
}


export function customerBrowseShopItem(shopId) {
    let url = "/shop/listOnShelfShopItem/"+shopId
    return request({
        url: url,
        method: 'get',
    })
}
export function customerAddOrder(customerId,shopId) {
    let url='/customer/addOrder/'+customerId+'/'+shopId
    return request({
        url: url,
        method: 'get'
    })
}

export function customerSelectShopItem(customerId,shopId,orderId,itemId,quantity) {
    let url = "/customer/selectShopItem/"+customerId+"/"+shopId+"/"+orderId+"/"+itemId+"/"+quantity
    return request({
        url: url,
        method: 'get',
    })
}

export function businessConfirm(businessId,shopId,orderId) {
    let url = "/business/confirmOrders/"+businessId+"/"+shopId+"/"+orderId
    return request({
        url: url,
        method: 'get',
    })
}

export function businessRefund(businessId,shopId,orderId) {
    let url = "/business/refund/"+businessId+"/"+shopId+"/"+orderId
    return request({
        url: url,
        method: 'get',
    })
}



export function shopOnShelf(shopId,itemId) {
    let url='/shop/onShelf/'+shopId+'/'+itemId
    return request({
        url: url,
        method: 'get'
    })
}
export function shopOffShelf(shopId,itemId) {
    let url='/shop/offShelf/'+shopId+'/'+itemId
    return request({
        url: url,
        method: 'get'
    })
}
export function getPrice(shopId,itemId) {
    let url='/shopItem/getPrice/'+shopId+'/'+itemId
    return request({
        url: url,
        method: 'get'
    })
}

export function customerPayOrder(customerId,orderId) {
    let url='/customer/payOrder/'+customerId+'/'+orderId
    return request({
        url: url,
        method: 'get'
    })
}
export function customerDeleteOrder(orderId) {
    let url='/customer/deleteOrder/'+orderId
    return request({
        url: url,
        method: 'get'
    })
}
export function businessWatchOrder(businessId) {
    let url='/business/watchOrders/'+businessId
    return request({
        url: url,
        method: 'get'
    })
}
export function customerlistOrder(data) { //如果后端是@RequestParam的话，直接改成post方法（前后端都是
    let url='/customer/get'
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function businessCreateItem(data) {
    let url='/business/createItem'
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function businessCreateShop(businessId, shopName){
    let url='/business/addShop/'+businessId+'/'+shopName
    return request(({
        url:url,
        method:'get'
    }))
}

export function shopListAvailableItem(businessId){
    let url='/shop/listAvailableItem/'+businessId
    return request(({
        url:url,
        method:'get'
    }))
}

export function shopAddShopItem(shopId,itemId,price){
    let url='/shop/createShopItem/'+shopId+'/'+itemId+'/'+price
    return request(({
        url:url,
        method:'get'
    }))
}
